package flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName FlyweightPatternDemo
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/3/9 16:29
 * @Version 1.0
 */
public class FlyweightPatternDemo {
	public interface Flyweight{
		void operate();
	}

	public class concreteFlyweight implements Flyweight{

		@Override
		public void operate() {

		}
	}

	public class FlyweightFactory {
		private Map<String, Flyweight> map = new HashMap<String, Flyweight>();

		public Flyweight getFlyweight(String key) {
			Flyweight flyweight = map.get(key);
			if (flyweight == null) {
				flyweight = new concreteFlyweight();
				map.put(key, flyweight);
			}//add1
			return flyweight;
		}
	}
}
